home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-STLport.exe / {app} / include / CEGUIProperty.h < prev    next >
C/C++ Source or Header  |  2005-07-21  |  5KB  |  191 lines

  1. /************************************************************************
  2.     filename:     CEGUIProperty.h
  3.     created:    21/2/2004
  4.     author:        Paul D Turner
  5.     
  6.     purpose:    Defines the Property class which forms part of a
  7.                 PropertySet
  8. *************************************************************************/
  9. /*************************************************************************
  10.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  11.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  12.  
  13.     This library is free software; you can redistribute it and/or
  14.     modify it under the terms of the GNU Lesser General Public
  15.     License as published by the Free Software Foundation; either
  16.     version 2.1 of the License, or (at your option) any later version.
  17.  
  18.     This library is distributed in the hope that it will be useful,
  19.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  21.     Lesser General Public License for more details.
  22.  
  23.     You should have received a copy of the GNU Lesser General Public
  24.     License along with this library; if not, write to the Free Software
  25.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  26. *************************************************************************/
  27. #ifndef _CEGUIProperty_h_
  28. #define _CEGUIProperty_h_
  29.  
  30. #include "CEGUIBase.h"
  31. #include "CEGUIString.h"
  32.  
  33.  
  34. // Start of CEGUI namespace section
  35. namespace CEGUI
  36. {
  37.  
  38. /*!
  39. \brief
  40.     Dummy base class to ensure correct casting of receivers.
  41. */
  42. class CEGUIEXPORT PropertyReceiver
  43. {
  44. public:
  45.     PropertyReceiver() {}
  46.     virtual ~PropertyReceiver() {}
  47. };
  48.  
  49.  
  50. /*!
  51. \brief
  52.     An abstract class that defines the interface to access object properties by name.
  53.  
  54.     Property objects allow (via a PropertySet) access to certain properties of objects
  55.     by using simple get/set functions and the name of the property to be accessed.
  56. */
  57. class CEGUIEXPORT Property
  58. {
  59. public:
  60.     /*!
  61.     \brief
  62.         Creates a new Property object.
  63.  
  64.     \param name
  65.         String containing the name of the new Property.
  66.  
  67.     \param help
  68.         String containing a description of the Property and it's usage.
  69.         
  70.     \param defaultValue
  71.         String holding the textual representation of the default value for this Property
  72.  
  73.     \param writesXML
  74.         Specifies whether the writeXMLToStream method should do anything for this Property.  This
  75.         enables selectivity in what properties within a PropertySet will get output as XML.
  76.     */
  77.     Property(const String& name, const String& help, const String& defaultValue = "", bool writesXML = true) :
  78.       d_name(name),
  79.       d_help(help),
  80.       d_default(defaultValue),
  81.       d_writeXML(writesXML)
  82.     {
  83.     }
  84.  
  85.  
  86.     /*!
  87.     \brief
  88.         Destructor for Property objects
  89.     */
  90.     virtual ~Property(void) {}
  91.  
  92.  
  93.     /*!
  94.     \brief
  95.         Return a String that describes the purpose and usage of this Property.
  96.  
  97.     \return
  98.         String that contains the help text
  99.     */
  100.     const String& getHelp(void) const        {return d_help;}
  101.  
  102.  
  103.     /*!
  104.     \brief
  105.         Return a the name of this Property
  106.  
  107.     \return
  108.         String containing the name of the Property
  109.     */
  110.     const String& getName(void) const        {return d_name;}
  111.  
  112.  
  113.     /*!
  114.     \brief
  115.         Return the current value of the Property as a String
  116.  
  117.     \param receiver
  118.         Pointer to the target object.
  119.  
  120.     \return
  121.         String object containing a textual representation of the current value of the Property
  122.     */
  123.     virtual String    get(const PropertyReceiver* receiver) const = 0;
  124.  
  125.  
  126.     /*!
  127.     \brief
  128.         Sets the value of the property
  129.  
  130.     \param receiver
  131.         Pointer to the target object.
  132.  
  133.     \param value
  134.         A String object that contains a textual representation of the new value to assign to the Property.
  135.  
  136.     \return
  137.         Nothing.
  138.  
  139.     \exception InvalidRequestException    Thrown when the Property was unable to interpret the content of \a value.
  140.     */
  141.     virtual void    set(PropertyReceiver* receiver, const String& value) = 0;
  142.  
  143.  
  144.     /*!
  145.     \brief
  146.         Returns whether the property is at it's default value.
  147.  
  148.     \param receiver
  149.         Pointer to the target object.
  150.  
  151.     \return
  152.         - true if the property has it's default value.
  153.         - false if the property has been modified from it's default value.
  154.     */
  155.     virtual bool    isDefault(const PropertyReceiver* receiver) const;
  156.  
  157.  
  158.     /*!
  159.     \brief
  160.         Returns the default value of the Property as a String.
  161.  
  162.     \param receiver
  163.         Pointer to the target object.
  164.  
  165.     \return
  166.         String object containing a textual representation of the default value for this property.
  167.     */
  168.     virtual String    getDefault(const PropertyReceiver* receiver) const;
  169.  
  170.  
  171.     /*!
  172.     \brief
  173.         Writes out an XML representation of this class to the given stream.
  174.  
  175.     \note
  176.         This would normally have been implemented via XMLGenerator base class, but in this
  177.         case we require the target PropertyReceiver in order to obtain the property value.
  178.     */
  179.     void writeXMLToStream(const PropertyReceiver* receiver, OutStream& out_stream) const;
  180.  
  181. protected:
  182.     String    d_name;        //!< String that stores the Property name.
  183.     String    d_help;        //!< String that stores the Property help text.
  184.     String    d_default;    //!< String that stores the Property default value string.
  185.     bool    d_writeXML; //!< Specifies whether writeXMLToStream should do anything for this property.
  186. };
  187.  
  188. } // End of  CEGUI namespace section
  189.  
  190. #endif    // end of guard _CEGUIProperty_h_
  191.